package com.yy.school.util;

import com.yy.school.vo.ScoreVO;

import java.util.ArrayList;
import java.util.List;

public class ScoreDBUtil extends DBUtil {

    //查询个人成绩
    public List<ScoreVO> getScoreBySid(Integer sid) {
        List<ScoreVO> list = new ArrayList<>();
        try {
            getConn();
            String sql = "SELECT stu.sid,stu.sname,c.cname,c.score from student stu,course c,score s\n" +
                    "where stu.sid=s.sid and\n" +
                    "s.cid=c.cid and stu.sid=?";
            ps = conn.prepareStatement(sql);
            ps.setObject(1, sid);
            rs = ps.executeQuery();
            while (rs.next()) {
                ScoreVO scoreVO = new ScoreVO(
                        rs.getInt(1),
                        rs.getString(2),
                        rs.getString(3),
                        rs.getInt(4)
                );
                list.add(scoreVO);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            closeConn();
        }
        return list;
    }


}
